#pragma once
#include <GRendererInfra/GRiCamera.h>
#include <GRendererInfra\GRiObj.h>

class GRTXRay;
class GRTXBVH;
class GRTXMesh;
class GRTXRenderer;
class GRTXObject;
class GRTXScene
{
public:
	static GRTXScene& Get();
	void InitRTX(std::vector<GUSPtr<GRiObj>>& SceneObjects, GUPtr<GRiCamera>& Camera, float width, float height, float PRR = 0.8,int maxPrimitive = 10);
protected:
	friend GRTXRenderer;

	float Width;
	float Height;
	float mPRR = 0.8;

	int MaxPrimitive = 15;
private:
	GUPtr<GRTXBVH> pNode;
	std::vector<GSPtr<GRTXMesh>> mObjs;
	GUSPtr<GRiCamera> pCamera;

private:
	void ResetObjs(std::vector<GUSPtr<GRiObj>>& SceneObjects);

private:
	// 返回对光源的采样点和pdf.
	void SampleLight(GRiVertex& samplePos, float& pdf)const;

	GRTXRay GenRay(float u, float v)const;
	
	GMath::Vector3 CastRay(const GRTXRay& ray)const;

	// 主
	void BuildBVH();

	// 次
	GUPtr<GRTXBVH> BuildBVH(std::vector<GSPtr<GRTXObject>> objs);
	GUPtr<GRTXBVH> RecursiveBuild(std::vector<GUPtr<GRTXBVH>>&& objs);
	/*GUPtr<GRTXBVH> RecursiveBuild(std::vector<GRTXBVH::Value> data);*/
};

